package com.zwk.cms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zwk.cms.entity.CrmBanner;
import com.zwk.cms.mapper.CrmBannerMapper;
import com.zwk.cms.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author zwk
 * @since 2022-08-27
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {

    @Autowired
    private CrmBannerMapper bannerMapper;

    // redis缓存
    @Cacheable(key = "'selectIndexList'", value = "banner")
    @Override
    public List<CrmBanner> selectAllBanner() {
        // 根据id降序排列, 获取前两条数据
//        QueryWrapper<CrmBanner> wrapper = new QueryWrapper<>();
//        wrapper.orderByDesc("id");
//        wrapper.last("limit 2");
//        return bannerMapper.selectList(wrapper);
        List<CrmBanner> list = bannerMapper.selectBanner();
        return list;
    }
}
